#ifndef WXSMITH_H
#define WXSMITH_H

#include <wx/splitter.h>
#include <wx/scrolwin.h>
#include <M_Code_plugin.h>
#include <sdk_events.h>
#include <tinyxml.h>
#include "wxsstoringsplitterwindow.h"
#include "wxsresourcetree.h"

class wxsProject;
class wxsItem;
class wxsResource;

class wxSmith : public M_Code_Plugin {
  public:
    wxSmith();
    ~wxSmith();
    static wxSmith* Get() { return m_Singleton; }
    int GetConfigurationGroup()  const { return cgEditor; }
    cbConfigurationPanel* GetConfigurationPanel( wxWindow* parent );
    virtual cbConfigurationPanel* GetProjectConfigurationPanel( wxWindow* parent, M_Code_Project* project );
    void BuildModuleMenu( const ModuleType type, wxMenu* menu, const FileTreeData* data = 0 );
    bool BuildToolBar( wxToolBar* toolBar );
    void OnAttach();
    void OnRelease( bool appShutDown );
    void RegisterScripting();
    void UnregisterScripting();
    wxsProject* GetSmithProject( M_Code_Project* Proj );
    M_Code_Project* GetM_Code_Project( wxsProject* Proj );
    inline wxsProject* operator[]( M_Code_Project* Proj ) { return GetSmithProject( Proj ); }
    inline M_Code_Project* operator[]( wxsProject* Proj ) { return GetM_Code_Project( Proj ); }
    void ShowResourcesTab();
  private:
    WX_DECLARE_HASH_MAP( M_Code_Project*, wxsProject*, wxPointerHash, wxPointerEqual, ProjectMapT );
    typedef ProjectMapT::iterator ProjectMapI;
    ProjectMapT m_ProjectMap;               ///< \brief Map binding all M_Code_Project classes with wxsProject ones
    wxsStoringSplitterWindow* m_Splitter;   ///< \brief Splitter window used to divide resource browser and property grid
    wxPanel* m_ResourceBrowserParent;       ///< \brief Parent panel for resource browser
    wxPanel* m_PropertyBrowserParent;       ///< \brief Parent for property browser
    int m_HookId;                           ///< \brief Project hook identifier used when deleting hook
    static wxSmith* m_Singleton;
    void OnProjectHook( M_Code_Project*, TiXmlElement*, bool );
    void OnProjectOpened( CodeBlocksEvent& event );
    void OnProjectClose( CodeBlocksEvent& event );
    void OnProjectRenamed( CodeBlocksEvent& event );
    void OnConfigure( wxCommandEvent& event );
    void OnMenu( wxCommandEvent& event );
    void BuildBrowsers();
    void BuildBrowserParents();
    static bool RecoverWxsFile( const wxString& WxsResourceSettings );
    void OnViewBrowsers( wxCommandEvent& event );
    void OnViewResourceBrowser( wxCommandEvent& event );
    void OnViewPropertyBrowser( wxCommandEvent& event );
    void OnUpdateUI( wxUpdateUIEvent& event );
    friend class wxSmithMime;
    DECLARE_EVENT_TABLE()
};

inline wxSmith* wxsPlugin() { return wxSmith::Get(); }
inline wxSmith* wxsProjectConv() { return wxSmith::Get(); }

#endif

